﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class SystemManage_SystemParamConfig_EmailSettings : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Check.CheckPermission("100100104");
        if (!IsPostBack)
        {
            List<Model.EMAILBODY> emailBodyList = new BLL.EMAILBODY().GetAllList();
            if (emailBodyList.Count > 0)
            {
                Model.EMAILBODY emailBody=emailBodyList[0];
                chk1.Checked = emailBody.ActivitySwitch == 1 ? true : false;
                chk2.Checked = emailBody.FindPasswordSwitch == 1 ? true : false;
                chk3.Checked = emailBody.RecommendMailSwitch == 1 ? true : false;
                chk4.Checked = emailBody.RegisterSwitch == 1 ? true : false;
                chk5.Checked = emailBody.OrderSwitch == 1 ? true : false;
                chk6.Checked = emailBody.PaySwitch == 1 ? true : false;
                chk7.Checked = emailBody.DeliverySwitch == 1 ? true : false;

                body1.Text = emailBody.ActivityBody;
                body2.Text = emailBody.FindPasswordBody;
                body3.Text = emailBody.RecommendMailBody;
                body4.Text = emailBody.RegisterBody;
                body5.Text = emailBody.OrderBody;
                body6.Text = emailBody.PayBody;
                body7.Text = emailBody.DeliveryBody;
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("100100104", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        List<Model.EMAILBODY> emailBodyList = new BLL.EMAILBODY().GetAllList();
        Model.EMAILBODY emailBody = null;

        if (emailBodyList.Count == 0)
        {//新增 
            emailBody = new Model.EMAILBODY();
        }
        else
        { //修改
            emailBody = emailBodyList[0];
        }

        emailBody.ActivitySwitch = chk1.Checked?1:0;
        emailBody.FindPasswordSwitch = chk2.Checked ? 1 : 0;
        emailBody.RecommendMailSwitch = chk3.Checked ? 1 : 0;
        emailBody.RegisterSwitch = chk4.Checked ? 1 : 0;
        emailBody.OrderSwitch = chk5.Checked ? 1 : 0;
        emailBody.PaySwitch = chk6.Checked ? 1 : 0;
        emailBody.DeliverySwitch = chk7.Checked ? 1 : 0;

        emailBody.ActivityBody = body1.Text;
        emailBody.FindPasswordBody = body2.Text;
        emailBody.RecommendMailBody = body3.Text;
        emailBody.RegisterBody = body4.Text;
        emailBody.OrderBody = body5.Text;
        emailBody.PayBody = body6.Text;
        emailBody.DeliveryBody = body7.Text;


        if (emailBodyList.Count == 0)
        {//新增 
            if (new BLL.EMAILBODY().Add(emailBody) > 0)
            { Share.Alert(this.Page, "保存成功"); return; }
        }
        else
        { //修改
            if (new BLL.EMAILBODY().Update(emailBody))
            { Share.Alert(this.Page, "保存成功"); return; }
        }
        Share.Alert(this.Page, "保存失败");
    }
}
